<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<script type="text/javascript" src="../../navigation_menu.js"></script>
		<script type="text/javascript" src="../../validation.js"></script>

		<!-- 调用导入预分配计划服务 -->
		<script type="text/javascript" src="../../SCADomain/scaDomain.js"></script>
		
		<script language="JavaScript">
			//var order_plan_text_item = new Array("计划编号", "航次", "总箱数", "大箱数");
			//var order_plan_text_name = new Array("id", "scd", "total", "big");
			//var order_plan_date_item = new Array("订舱开始时间", "订舱截止时间", "退舱截止时间");
			//var order_plan_date_name = new Array("start", "end", "cancel");

			function load() {
				menu_main('../../nav.xml', 'navigation_menu');
				//gen_order_plan();
			}
			/*
			function gen_order_plan() {
				var order_plan = document.getElementById("order_plan");

				var form = '<form>';
				for (var i = 0; i < order_plan_text_item.length; i++) {
					form = form + order_plan_text_item[i] + '：' + '<input type="text" name="' +
							order_plan_text_name[i] + '" id="' + order_plan_text_name[i] + '"><br/>';
				}
				form = form + '<input type="button" name="import" value="导入" onclick="import_order_plan();">' + 
						'<input type="button" name="query" value="查询" onclick="query_order_plan();">' +
						'<input type="reset" name="reset" value="重置">' + '</form>';

				//document.write(form);
				order_plan.innerHTML = form;
				//document.getElementByID('order_plan').innerHTML = form;
			}
			*/
			function validate_date(id) {
				if (isDate(document.getElementById(id).value) == false) {
					document.getElementById(id + "_msg").innerHTML = "请输入正确的日期";
					return false;
				} else {
					document.getElementById(id + "_msg").innerHTML = "";
					return true;
				}
			}
			function validate_order_plan() {
				var res = true;
				var date1, date2;

				//检查是否有数据输入
				if (checkEmpty(document.getElementById("id").value) == true) {
					document.getElementById("id_msg").innerHTML = "此项必填";
					res = false;
				}
				if (checkEmpty(document.getElementById("scd").value) == true) {
					document.getElementById("scd_msg").innerHTML = "此项必填";
					res = false;
				}
				//验证日期合法性
				if (validate_date("start") == false) {
					res = false;
				}
				if (validate_date("end") == false) {
					res = false;
				}
				if (validate_date("cancel") == false) {
					res = false;
				}
				//比较日期先后关系是否符合要求
				date1 = document.getElementById("start").value;
				date2 = document.getElementById("end").value;
				if (compareDate(date1, date2) == 1) {
					document.getElementById("start_msg").innerHTML = "订舱开始时间应在订舱截止时间前！";
					document.getElementById("end_msg").innerHTML = "订舱截止时间应在订舱开始时间后！";
					res = false;
				} else if (compareDate(date1, date2) != 2) {
					document.getElementById("start_msg").innerHTML = "";
					document.getElementById("end_msg").innerHTML = "";
				}
				date1 = document.getElementById("cancel").value;
				if (compareDate(date2, date1) == 1) {
					document.getElementById("end_msg").innerHTML = "订舱截止时间应在退舱截止时间前！";
					document.getElementById("cancel_msg").innerHTML = "退舱截止时间应在订舱截止时间后！";
					res = false;
				} else if (compareDate(date2, date1) != 2) {
					document.getElementById("end_msg").innerHTML = "";
					document.getElementById("cancel_msg").innerHTML = "";
				}
				//检验箱数是否，正整数，总箱数大于等于大箱数
				var total = document.getElementById("total").value;
				var big = document.getElementById("big").value;
				if (isInteger(total) == false) {
					document.getElementById("total_msg").innerHTML = "请输入正整数";
					res = false;
				} else if (checkEmpty(document.getElementById("total").value) == true) {
					document.getElementById("total_msg").innerHTML = "此项必填";
					res = false;
				} else {
					document.getElementById("total_msg").innerHTML = "";
				}
				if (isInteger(big) == false) {
					document.getElementById("big_msg").innerHTML = "请输入正整数";
					res = false;
				} else if (checkEmpty(document.getElementById("big").value) == true) {
					document.getElementById("big_msg").innerHTML = "此项必填";
					res = false;
				} else {
					document.getElementById("big_msg").innerHTML = "";
				}
				if (isInteger(total) == true && isInteger(big) == true) {
					var totalInt = parseInt(total, 10);
					var bigInt = parseInt(big, 10);
					if (totalInt < bigInt) {
						document.getElementById("total_msg").innerHTML = "总箱数应大于等于大箱数";
						document.getElementById("big_msg").innerHTML = "大箱数应小于等于总箱数";
						res = false;
					} else {
						document.getElementById("total_msg").innerHTML = "";
						document.getElementById("big_msg").innerHTML = "";
					}
				}
				return res;
			}
			function import_order_plan_response(answer) {
				if (answer) {
					alert("导入成功");
				} else {
					alert("导入失败");
				}
			}
			function import_order_plan() {
				if(validate_order_plan() == true) {
					//定义类order_plan JSON
					var order_plan = {
						id: document.getElementById("id").value,
						scd: document.getElementById("scd").value,
						start: document.getElementById("start").value,
						end: document.getElementById("end").value,
						cancel: document.getElementById("cancel").value,
						total: parseInt(document.getElementById("total").value),
						big: parseInt(document.getElementById("big").value)
					}	

					OrderPlanImportService.post(order_plan, import_order_plan_response());
				} else {
					alert("数据有误，请重新输入！");
				}
			}
			function query_order_plan() {
				
			}
		</script>
		
		<title>导入舱位预分配计划</title>
	</head>

	<body onload="load();">
		<h1>导入舱位预分配计划</h1>
		
		<!-- 导航菜单 -->
		<div id="navigation_menu"></div>
		
		<div id="order_plan_management">
			<!-- 订舱计划表单 -->
			<fieldset>
			<legend>订舱计划</legend>
			<form id="order_plan">
				<label for="id">计划编号：</label><input type="text" name="id" id="id"><a id="id_msg"></a><br/>
				<label for="scd">航次：</label><input type="text" name="scd" id="scd"><a id="scd_msg"></a><br/>
				<label for="start">订舱开始时间(MM/DD/YYYY)：</label><input type="text" name="start" id="start" maxlength="10"><a id="start_msg"></a><br/>
				<label for="end">订舱截止时间(MM/DD/YYYY)：</label><input type="text" name="end" id="end" maxlength="10"><a id="end_msg"></a><br/>
				<label for="cancel">退舱截止时间(MM/DD/YYYY)：</label><input type="text" name="cancel" id="cancel" maxlength="10"><a id="cancel_msg"></a><br/>
				<label for="total">总箱数：</label><input type="text" name="total" id="total"><a id="total_msg"></a><br/>
				<label for="big">大箱数：</label><input type="text" name="big" id="big"><a id="big_msg"></a><br/>
				<input type="button" name="import" value="导入" onclick="import_order_plan();">
				<input type="button" name="query" value="查询" onclick="query_order_plan();">
				<input type="reset" name="reset" value="重置">
			</form>
			</fieldset>
		</div>
		
	</body>
</html>